package hanjia;

import suanfa.ListNode;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/10-下午1:15
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode203 {

    public ListNode removeElements(ListNode head, int val) {

        if (head==null){
            return null;
        }

        if (head.val!=val){
            head.next=removeElements(head.next,val);
            return head;
        }else {
            return removeElements(head.next,val);
        }


    }

    public ListNode removeElements2(ListNode head, int val) {
        if (head==null){
            return null;
        }


        ListNode node1=head;
        ListNode node2=head.next;
        while (node2!=null){

            if (node2.val==val){
                node2=node2.next;
                node1.next=node2;
            }else {
                node1=node2;
                node2=node2.next;

            }




        }
        if (head.val==val){
            return head.next;
        }


        return head;
    }
}
